let person = {
  name:'张三',
  age:18,
}

//vue2
let p = {}
Object.defineProperty(p,'name',{
  // 当且仅当该属性的 configurable 为 true 时，该属性描述符才能够被改变
  // 同时该属性也能从对应的对象上被删除。默认为 false。
  configurable:true,
  get(){
    console.log('读取name:'+name)
    return person.name
  },
  set(value){
    console.log('修改name:'+name)
    person.name = value
  }
})

//vue3
const p1 = new Proxy(person,{
  //读取属性
  get(target,propName){
    console.log('读取:',propName)
    //return target[propName]
    return Reflect.get(target,propName)
  },
  //可以修改属性也可以增加属性
  set(target,propName,value){
    console.log('修改:',propName)
    //target[propName] = value
    Reflect.set(target,propName,value)
  },
  //删除属性
  deleteProperty(target, propName) {
    console.log('删除:',propName)
    //return delete target[propName]
    return Reflect.deleteProperty(target,propName)
  }
})
